package com.ruoyi.system.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.MingChinaCity;
import com.ruoyi.system.service.IMingChinaCityService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 中国城市定义Controller
 * 
 * @author ruoyi
 * @date 2023-03-12
 */
@RestController
@RequestMapping("/system/city")
public class MingChinaCityController extends BaseController
{
    @Autowired
    private IMingChinaCityService mingChinaCityService;

    /**
     * 查询中国城市定义列表
     */
    @PreAuthorize("@ss.hasPermi('system:city:list')")
    @GetMapping("/list")
    public TableDataInfo list(MingChinaCity mingChinaCity)
    {
        startPage();
        List<MingChinaCity> list = mingChinaCityService.selectMingChinaCityList(mingChinaCity);
        return getDataTable(list);
    }

    /**
     * 导出中国城市定义列表
     */
    @PreAuthorize("@ss.hasPermi('system:city:export')")
    @Log(title = "中国城市定义", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, MingChinaCity mingChinaCity)
    {
        List<MingChinaCity> list = mingChinaCityService.selectMingChinaCityList(mingChinaCity);
        ExcelUtil<MingChinaCity> util = new ExcelUtil<MingChinaCity>(MingChinaCity.class);
        util.exportExcel(response, list, "中国城市定义数据");
    }

    /**
     * 获取中国城市定义详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:city:query')")
    @GetMapping(value = "/{locationId}")
    public AjaxResult getInfo(@PathVariable("locationId") Long locationId)
    {
        return success(mingChinaCityService.selectMingChinaCityByLocationId(locationId));
    }

    /**
     * 新增中国城市定义
     */
    @PreAuthorize("@ss.hasPermi('system:city:add')")
    @Log(title = "中国城市定义", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody MingChinaCity mingChinaCity)
    {
        return toAjax(mingChinaCityService.insertMingChinaCity(mingChinaCity));
    }

    /**
     * 修改中国城市定义
     */
    @PreAuthorize("@ss.hasPermi('system:city:edit')")
    @Log(title = "中国城市定义", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody MingChinaCity mingChinaCity)
    {
        return toAjax(mingChinaCityService.updateMingChinaCity(mingChinaCity));
    }

    /**
     * 删除中国城市定义
     */
    @PreAuthorize("@ss.hasPermi('system:city:remove')")
    @Log(title = "中国城市定义", businessType = BusinessType.DELETE)
	@DeleteMapping("/{locationIds}")
    public AjaxResult remove(@PathVariable Long[] locationIds)
    {
        return toAjax(mingChinaCityService.deleteMingChinaCityByLocationIds(locationIds));
    }
}
